<!DOCTYPE HTML>
<html>
  <head>
		<title>演示了ECB模式前后端协商R0、RC</title>
		<meta charset="utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<meta name="viewport" content="initial-scale=1,width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, viewport-fit=cover">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta content="yes" name="apple-touch-fullscreen">
		<meta name="App-Config" content="fullscreen=yes,useHistoryState=yes,transition=yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no">
		<script type="text/javascript" src="./js/jquery-2.1.4.min.js"></script>
		<script type="module">
			import messageguard from "./js/microdone.js"
			var license = "dHlPWDZDckxMQTl3N3F1YUlBWkoxcS9GUkRBQXBLR0hFM3M0UHI1emNpOE1kNytlVGU4TGJlVEhQdmNISEJZOUgrMnRuRGZMRUJvQmtjbzI1K0VwV3pQeW81ZXQ4YkR5ZzJqQXVsbjZJRmlWcjBFK21vQytjQk5PUDAwNERXUFRjU3JIL2dyN091ZndFclRXT05kMHE5bWhiSWpoalBHZExxdHBOSlBSMS9VPXsiaWQiOjAsInR5cGUiOiJ0ZXN0IiwicGxhdGZvcm0iOjEwLCJub3RiZWZvcmUiOiIyMDIyMDMzMCIsIm5vdGFmdGVyIjoiMjAyMjA5MzAifQ==";
			window.mg = new messageguard(license);
			//window.urltemp = "http://127.0.0.1:8081/DemoSFZFBWJMJMJServer";
			//本页面用于测试演示了ECB模式前后端协商R0、RC，对应的服务端示例是com.serv.genR0、com.serv.decryptECB类
			//运行此示例时，需要打开F12开发者工具console看初始化结果
			$.ajax({
				url: "/test/genR0",
				data:{},
				dataType : "jsonp",
				jsonp : "jsoncallback",
				contentType : "application/json;utf-8",
				success:function(retobj){
					if(retobj.code == "0"){
						var r0enstr = retobj.message;
						var resobj = mg.cDecryptR0EnStr(r0enstr);
						if(resobj.code == "0"){
							console.log("客户端解密R0密文成功:" + JSON.stringify(resobj));
							//客户端加密报文，同时返回rnpie
							var str = "哈喽，我是客户端！！！";
							var pubid = 2;
							var xy = "DBFE5845DC96F9EE4100560A4C4F30038A79B0C00B279C7C742771114BC85E2D85C41F9E259D91D25042E7FFA3565C34E4F4325C6181E7721468B318F5E148A4";
							var resobj = mg.cEncryptByECBAndHmacInit(str,xy);
							if(resobj.code == "0"){
								//向后端发送密文
								$.ajax({
									url:  "/test/decryptECB",
									data:{"enstr":resobj.message,"rnpie":resobj.rnpie,"pubid":pubid},
									dataType : "jsonp",
									jsonp : "jsoncallback",
									contentType : "application/json;utf-8",
									success:function(retobj){
										//输出服务端解密结果
										console.log("服务端解密结果:" + decodeURIComponent(JSON.stringify(retobj)));
									},
								});
							}else{
								console.log("客户端加密报错:" + JSON.stringify(resobj));
							}
						}else{
							console.log("解密R0密文失败");
							console.log(JSON.stringify(resobj));
						}
					}else{
						console.log(JSON.stringify(retobj));
					}
					
				}
			});
		</script>
	</head>
 <body>
	演示了ECB模式客户端加密报文服务端解密报文<br/>
 	请打开F12开发者工具console观察结果
 </body>
</html>
